/* 
 * UNIVERSIDAD DEL VALLE DE GUATEMALA 
 * ALGORITIMOS Y ESTRUCTURAS DE DATOS - SECCION 20
 * INTEGRANTES:     KEVIN GONZALEZ, 11499
 *                  SERGIO ARGUETA, 11029
 *                  PEDRO CASTILLO, 11009
 *                  JAVIER CASTILLO, 11010
 * DECRIPCION: CLASE MAIN IMPLEMENTADA PARA LA CALCULADORA, AQUI ESTA EL GUI.
 */
import java.util.Vector;

public class CalcPedro extends javax.swing.JFrame
{
    
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(CalcPedro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(CalcPedro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(CalcPedro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(CalcPedro.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold

        /* Create and display the form */
        Factory opcion = new Factory();
        int result = opcion.GetInterfaz();

        if (result==1)
        {
            Stack<String> MyStack = opcion.Evaluate();
        }
        else
        {
            ListInterface<String> MyOtherStack = opcion.EvaluateOther();
        }
            
        
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new CalcPedro().setVisible(true);
            }
        });
    }
    /** Creates new form CalcPedro */
    public CalcPedro() {
        initComponents();
    }

    // Atributos para operacions.
    int entero, Resultado;
    String Num = "";
    String TotalNum = "", Result="";
    StackVector<String> ecuacion = new StackVector<String>();
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jButton7 = new javax.swing.JButton();
        jButton8 = new javax.swing.JButton();
        jButton9 = new javax.swing.JButton();
        jButton10 = new javax.swing.JButton();
        jButton11 = new javax.swing.JButton();
        jButton12 = new javax.swing.JButton();
        jButton13 = new javax.swing.JButton();
        jButton14 = new javax.swing.JButton();
        jButton15 = new javax.swing.JButton();
        jButton16 = new javax.swing.JButton();
        jButton17 = new javax.swing.JButton();
        jTextField1 = new javax.swing.JTextField();
        jLabel1 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Calculadora");
        setBackground(new java.awt.Color(0, 0, 0));

        jButton1.setText("1");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });

        jButton2.setText("2");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jButton3.setText("3");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });

        jButton4.setText("4");
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });

        jButton5.setText("5");
        jButton5.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });

        jButton6.setText("6");
        jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });

        jButton7.setText("7");
        jButton7.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });

        jButton8.setText("8");
        jButton8.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton8ActionPerformed(evt);
            }
        });

        jButton9.setText("9");
        jButton9.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton9ActionPerformed(evt);
            }
        });

        jButton10.setText("0");
        jButton10.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton10ActionPerformed(evt);
            }
        });

        jButton11.setText("Borrar");
        jButton11.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton11ActionPerformed(evt);
            }
        });

        jButton12.setText("ESPACIO");
        jButton12.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton12ActionPerformed(evt);
            }
        });

        jButton13.setText("  +  ");
        jButton13.setMaximumSize(new java.awt.Dimension(45, 23));
        jButton13.setMinimumSize(new java.awt.Dimension(45, 23));
        jButton13.setPreferredSize(new java.awt.Dimension(45, 23));
        jButton13.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton13ActionPerformed(evt);
            }
        });

        jButton14.setText("  -  ");
        jButton14.setMaximumSize(new java.awt.Dimension(45, 23));
        jButton14.setMinimumSize(new java.awt.Dimension(45, 23));
        jButton14.setPreferredSize(new java.awt.Dimension(45, 23));
        jButton14.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton14ActionPerformed(evt);
            }
        });

        jButton15.setText("x");
        jButton15.setMaximumSize(new java.awt.Dimension(45, 23));
        jButton15.setMinimumSize(new java.awt.Dimension(45, 23));
        jButton15.setPreferredSize(new java.awt.Dimension(45, 23));
        jButton15.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton15ActionPerformed(evt);
            }
        });

        jButton16.setText("/");
        jButton16.setMaximumSize(new java.awt.Dimension(45, 23));
        jButton16.setMinimumSize(new java.awt.Dimension(45, 23));
        jButton16.setPreferredSize(new java.awt.Dimension(45, 23));
        jButton16.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton16ActionPerformed(evt);
            }
        });

        jButton17.setText("=");
        jButton17.setMaximumSize(new java.awt.Dimension(45, 23));
        jButton17.setMinimumSize(new java.awt.Dimension(45, 23));
        jButton17.setPreferredSize(new java.awt.Dimension(45, 23));
        jButton17.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton17ActionPerformed(evt);
            }
        });

        jTextField1.setEditable(false);
        jTextField1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));

        jLabel1.setText("                         CALCULADORA");

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(50, 50, 50)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
                    .addComponent(jTextField1, javax.swing.GroupLayout.DEFAULT_SIZE, 224, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jButton12, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jButton1)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton2)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton3))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                                .addComponent(jButton10)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addComponent(jButton11, javax.swing.GroupLayout.PREFERRED_SIZE, 84, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jButton15, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
                            .addComponent(jButton17, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)
                            .addComponent(jButton16, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton4)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton14, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jButton7)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton8)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton9)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jButton13, javax.swing.GroupLayout.DEFAULT_SIZE, 89, Short.MAX_VALUE)))
                .addGap(50, 50, 50))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGap(30, 30, 30)
                .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jTextField1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton7)
                    .addComponent(jButton8)
                    .addComponent(jButton9)
                    .addComponent(jButton13, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton4)
                    .addComponent(jButton5)
                    .addComponent(jButton6)
                    .addComponent(jButton14, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton1)
                    .addComponent(jButton2)
                    .addComponent(jButton3)
                    .addComponent(jButton15, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton10)
                    .addComponent(jButton11)
                    .addComponent(jButton16, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton12)
                    .addComponent(jButton17, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(44, 44, 44))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents
// Buttonlisteners. Verifican si el botón fue presionado. (Línea 282-507)
private void jButton10ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton10ActionPerformed
// TODO add your handling code here:
    TotalNum = TotalNum + "0";
    Num = Num + "0";
    jTextField1.setText(TotalNum);
}//GEN-LAST:event_jButton10ActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
// TODO add your handling code here:
    TotalNum = TotalNum + "1";
    Num = Num + "1";
    jTextField1.setText(TotalNum);
}//GEN-LAST:event_jButton1ActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
// TODO add your handling code here:
    TotalNum = TotalNum + "2";
    Num = Num + "2";
    jTextField1.setText(TotalNum);
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
// TODO add your handling code here:
    TotalNum = TotalNum + "3";
    Num = Num + "3";
    jTextField1.setText(TotalNum);
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
// TODO add your handling code here:
    TotalNum = TotalNum + "4";
    Num = Num + "4";
    jTextField1.setText(TotalNum);
}//GEN-LAST:event_jButton4ActionPerformed

private void jButton5ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton5ActionPerformed
// TODO add your handling code here:
    TotalNum = TotalNum + "5";
    Num = Num + "5";
    jTextField1.setText(TotalNum);
}//GEN-LAST:event_jButton5ActionPerformed

private void jButton6ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton6ActionPerformed
// TODO add your handling code here:
    TotalNum = TotalNum + "6";
    Num = Num + "6";
    jTextField1.setText(TotalNum);
}//GEN-LAST:event_jButton6ActionPerformed

private void jButton7ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton7ActionPerformed
// TODO add your handling code here:
    TotalNum = TotalNum + "7";
    Num = Num + "7";
    jTextField1.setText(TotalNum);
}//GEN-LAST:event_jButton7ActionPerformed

private void jButton8ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton8ActionPerformed
// TODO add your handling code here:
    TotalNum = TotalNum + "8";
    Num = Num + "8";
    jTextField1.setText(TotalNum);
}//GEN-LAST:event_jButton8ActionPerformed

private void jButton9ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton9ActionPerformed
// TODO add your handling code here:
    TotalNum = TotalNum + "9";
    Num = Num + "9";
    jTextField1.setText(TotalNum);
}//GEN-LAST:event_jButton9ActionPerformed
//Nos permite sumar si el stack no esta vacío.
private void jButton13ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton13ActionPerformed
// TODO add your handling code here:// SUMAR
    TotalNum = TotalNum + "+";
    Num = "+";
    jTextField1.setText(TotalNum);
            if(!ecuacion.empty())
            {
                if(ecuacion.size()<2)
                {
                    Result = ecuacion.pop();
                }
                else
                {
                    int i;
                    for (i=0; i<=ecuacion.size(); i++)
                    {
                        Resultado = Resultado + Integer.parseInt(ecuacion.pop());
                    }
                    Result = Integer.toString(Resultado);
                }
            }
}//GEN-LAST:event_jButton13ActionPerformed
// Nos permite borrar la ecuacion si nos confundimos.
private void jButton11ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton11ActionPerformed
// TODO add your handling code here: BORRAR
    TotalNum = "";
    Num = "";
    Result = "";
    Resultado = 0;
    while(!ecuacion.empty())
    {
        ecuacion.pop();
    }
    jTextField1.setText(TotalNum);
}//GEN-LAST:event_jButton11ActionPerformed
//Nos permite generar espacios y va sumando los datos conforme se escribe el codigo en la calculadora.
private void jButton12ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton12ActionPerformed
// TODO add your handling code here: ESPACIO
    try{
        entero = Integer.parseInt(Num);
        ecuacion.push(Num);
    }catch(Exception e){
//        if (Num.equals("+"))//Nos permite sumar si el stack no esta vacio
//        {
//            if(!ecuacion.empty())
//            {
//                if(ecuacion.size()<2)
//                {
//                    Result = ecuacion.pop();
//                }
//                else
//                {
//                    int i;
//                    for (i=0; i<=ecuacion.size(); i++)
//                    {
//                        Resultado = Resultado + Integer.parseInt(ecuacion.pop());
//                    }
//                    Result = Integer.toString(Resultado);
//                }
//            }
//        }
//        if (Num.equals("-"))//Nos permite restar si el stack no esta vacio
//        {
//            if(!ecuacion.empty())
//            {
//                if(ecuacion.size()<2)
//                {
//                    Result = ecuacion.pop();
//                }
//                else
//                {
//                    int i;
//                    int first = Integer.parseInt(ecuacion.pop());
//                    int second = Integer.parseInt(ecuacion.pop());
//                    Resultado = Resultado + second - first;
//                    for (i=0; i<=ecuacion.size(); i++)
//                    {
//                        Resultado = Resultado - Integer.parseInt(ecuacion.pop());
//                    }
//                    Result = Integer.toString(Resultado);
//                }
//            }
//                /*int i;
//                for (i=0; i<=ecuacion.size(); i++)
//                {
//                    Resultado = Resultado - Integer.parseInt(ecuacion.pop());
//                }
//                Result = Integer.toString(Resultado);*/
//        }
//        if (Num.equals("x"))
//        {
//            if(!ecuacion.empty())//Nos permite multiplicar si el stack no esta vacio
//            {
//                int i;
//                if (Resultado==0)
//                {
//                    Resultado = 1;
//                    for (i=0; i<=ecuacion.size(); i++)
//                    {
//                        Resultado = Resultado * Integer.parseInt(ecuacion.pop());
//                    }
//                    Result = Integer.toString(Resultado);
//                }
//                else
//                {
//                    for (i=0; i<=ecuacion.size(); i++)
//                    {
//                        Resultado = Resultado * Integer.parseInt(ecuacion.pop());
//                    }
//                    Result = Integer.toString(Resultado);
//                }
//                
//                /*for (i=0; i<=ecuacion.size(); i++)
//                {
//                    Resultado = Resultado * Integer.parseInt(ecuacion.pop());
//                }
//                Result = Integer.toString(Resultado);*/
//            }
//        }
//        if (Num.equals("/"))//Nos permite dividir si el stack no esta vacio y si no hay un 0 en la ecuacion.
//        {
//            if(!ecuacion.empty())
//            {
//                if(ecuacion.size()<2)
//                {
//                    Result = ecuacion.pop();
//                }
//                else
//                {
//                    int i;
//                    if (Resultado==0)
//                    {
//                        int first = Integer.parseInt(ecuacion.pop());
//                        int second = Integer.parseInt(ecuacion.pop());
//                        Resultado = second / first;
//                        for (i=0; i<=ecuacion.size(); i++)
//                        {
//                            Resultado = Resultado / Integer.parseInt(ecuacion.pop());
//                        }
//                    }
//                    else
//                    {
//                        for (i=0; i<=ecuacion.size(); i++)
//                        {
//                            Resultado = Resultado / Integer.parseInt(ecuacion.pop());
//                        }
//                    }
//                    Result = Integer.toString(Resultado);
//                }
//                /*int i;
//                for (i=0; i<=ecuacion.size(); i++)
//                {
//                    if(ecuacion.peek()=="0")
//                    {
//                        Result = "No esta definido esa operacion";
//                    }
//                    else
//                    {
//                        Resultado = Resultado / Integer.parseInt(ecuacion.pop());
//                    }
//                }
//                Result = Integer.toString(Resultado);*/
//            }
//        }
    }
    Result = Integer.toString(Resultado);
    TotalNum = TotalNum + " ";
    Num = "";
    jTextField1.setText(TotalNum);
}//GEN-LAST:event_jButton12ActionPerformed
//Nos permite restar si el stack no esta vacío.
private void jButton14ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton14ActionPerformed
// TODO add your handling code here: RESTAR
    TotalNum = TotalNum + "-";
    Num = "-";
    jTextField1.setText(TotalNum);
            if(!ecuacion.empty())
            {
                if(ecuacion.size()<2&&Resultado==0)
                {
                    Result = ecuacion.pop();
                }
                else
                {
                    int i;
                    if (Resultado == 0)
                    {
                        String first = ecuacion.pop();
                        int second = Integer.parseInt(ecuacion.pop());
                        ecuacion.push(first);
                        Resultado = Resultado + second;
                        for (i=0; i<=ecuacion.size(); i++)
                        {
                            Resultado = Resultado - Integer.parseInt(ecuacion.pop());
                        }
                        Result = Integer.toString(Resultado);
                    }
                    else
                    {
                        for (i=0; i<=ecuacion.size(); i++)
                        {
                            Resultado = Resultado - Integer.parseInt(ecuacion.pop());
                        }
                        Result = Integer.toString(Resultado);
                    }
                }
            }
}//GEN-LAST:event_jButton14ActionPerformed
//Nos permite multiplicar si el stack no esta vacío.
private void jButton15ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton15ActionPerformed
// TODO add your handling code here: MULTIPLICAR
    TotalNum = TotalNum + "x";
    Num = "x";
    jTextField1.setText(TotalNum);
            if(!ecuacion.empty())
            {
                int i;
                if (Resultado==0)
                {
                    Resultado = 1;
                    for (i=0; i<=ecuacion.size(); i++)
                    {
                        Resultado = Resultado * Integer.parseInt(ecuacion.pop());
                    }
                    Result = Integer.toString(Resultado);
                }
                else
                {
                    for (i=0; i<=ecuacion.size(); i++)
                    {
                        Resultado = Resultado * Integer.parseInt(ecuacion.pop());
                    }
                    Result = Integer.toString(Resultado);
                }
            }
}//GEN-LAST:event_jButton15ActionPerformed
//Nos permite dividir si el stack no esta vacío.
private void jButton16ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton16ActionPerformed
// TODO add your handling code here: DIVIDE
    TotalNum = TotalNum + "/";
    Num = "/";
    jTextField1.setText(TotalNum);
            if(!ecuacion.empty())
            {
                if(ecuacion.size()<2)
                {
                    Result = ecuacion.pop();
                }
                else
                {
                    int i;
                    if (Resultado==0)
                    {
                        if (ecuacion.size()==2)
                        {
                            int first = Integer.parseInt(ecuacion.pop());
                            int second = Integer.parseInt(ecuacion.pop());
                            Resultado = second / first;
                        }
                        else
                        {
                            int first = Integer.parseInt(ecuacion.pop());
                            int second = Integer.parseInt(ecuacion.pop());
                            Resultado = second / first;
                            for (i=0; i<=ecuacion.size(); i++)
                            {
                                Resultado = Resultado / Integer.parseInt(ecuacion.pop());
                            }
                        }
                    }
                    else
                    {
                        for (i=0; i<=ecuacion.size(); i++)
                        {
                            Resultado = Resultado / Integer.parseInt(ecuacion.pop());
                        }
                    }
                    Result = Integer.toString(Resultado);
                }
            }
}//GEN-LAST:event_jButton16ActionPerformed
//Da el resultado.
private void jButton17ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton17ActionPerformed
// TODO add your handling code here: IGUAL
    jTextField1.setText(Result);
}//GEN-LAST:event_jButton17ActionPerformed

    /**
     * @param args the command line arguments
     */
    
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton10;
    private javax.swing.JButton jButton11;
    private javax.swing.JButton jButton12;
    private javax.swing.JButton jButton13;
    private javax.swing.JButton jButton14;
    private javax.swing.JButton jButton15;
    private javax.swing.JButton jButton16;
    private javax.swing.JButton jButton17;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JButton jButton7;
    private javax.swing.JButton jButton8;
    private javax.swing.JButton jButton9;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JTextField jTextField1;
    // End of variables declaration//GEN-END:variables
}
